package com.sumer.psychology.space.infrastructure.messaging.rabbitmq;

import com.sumer.psychology.common.port.adapter.messaging.Exchanges;
import com.sumer.psychology.common.port.adapter.messaging.rabbitmq.ExchangeListener;
import com.sumer.psychology.space.infrastructure.persistence.mongo.MongoRecommendationRepository;

/**
 * 推荐资源
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/12/9
 * Time: 15:16
 */
public class RecommendationMessageCreatedEventListener extends ExchangeListener {
    private MongoRecommendationRepository mongoRecommendationRepository;

    public RecommendationMessageCreatedEventListener(MongoRecommendationRepository mongoRecommendationRepository) {
        this.mongoRecommendationRepository = mongoRecommendationRepository;
    }

    @Override
    protected String exchangeName() {
        return Exchanges.DEFAULT_EXCHANGE_NAME;
    }

    @Override
    protected void filteredDispatch(String aType, String aTextMessage) {
        mongoRecommendationRepository().add(aTextMessage);
    }

    @Override
    protected String[] listensTo() {
        return new String[]{"com.sumer.psychology.sharing.domain.model.SharedResourceRecommendedEvent"};
    }

    private MongoRecommendationRepository mongoRecommendationRepository() {
        return mongoRecommendationRepository;
    }
}
